package day018.thread.demo2;

public class Ticket implements Runnable {
    private int ticketCount = 100;

    @Override
    public void run() {
        while (true) {
            synchronized (Ticket.class) {
                if (ticketCount <= 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticketCount--;
                    System.out.println(Thread.currentThread().getName() + "卖出一张票，剩下" + ticketCount + "张");
                }
            }
        }
    }
}
